{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用 Anaconda"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Anaconda](http://www.continuum.io/downloads)是一个很好用的Python IDE，它集成了很多科学计算需要使用的**python**第三方工具包。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## conda 的使用 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据自己的操作系统安装好[Anaconda](http://www.continuum.io/downloads)后，在命令行下输入：\n",
    "\n",
    "    conda list\n",
    "\n",
    "可以看已经安装好的**python**第三方工具包，这里我们使用 `magic` 命令 `%%cmd` 在 `ipython cell` 中来执行这个命令："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# packages in environment at C:\\Anaconda:\n",
      "#\n",
      "_license                  1.1                      py27_0  \n",
      "alabaster                 0.7.3                    py27_0  \n",
      "anaconda                  2.3.0                np19py27_0  \n",
      "argcomplete               0.8.9                    py27_0  \n",
      "astropy                   1.0.3                np19py27_0  \n",
      "babel                     1.3                      py27_0  \n",
      "backports.ssl-match-hostname 3.4.0.2                   <pip>\n",
      "basemap                   1.0.7                np19py27_0  \n",
      "bcolz                     0.9.0                np19py27_0  \n",
      "beautiful-soup            4.3.2                    py27_1  \n",
      "beautifulsoup4            4.3.2                     <pip>\n",
      "binstar                   0.11.0                   py27_0  \n",
      "bitarray                  0.8.1                    py27_1  \n",
      "blaze                     0.8.0                     <pip>\n",
      "blaze-core                0.8.0                np19py27_0  \n",
      "blz                       0.6.2                np19py27_1  \n",
      "bokeh                     0.9.0                np19py27_0  \n",
      "boto                      2.38.0                   py27_0  \n",
      "bottleneck                1.0.0                np19py27_0  \n",
      "cartopy                   0.13.0               np19py27_0  \n",
      "cdecimal                  2.3                      py27_1  \n",
      "certifi                   14.05.14                 py27_0  \n",
      "cffi                      1.1.0                    py27_0  \n",
      "clyent                    0.3.4                    py27_0  \n",
      "colorama                  0.3.3                    py27_0  \n",
      "conda                     3.17.0                   py27_0  \n",
      "conda-build               1.14.1                   py27_0  \n",
      "conda-env                 2.4.2                    py27_0  \n",
      "configobj                 5.0.6                    py27_0  \n",
      "cryptography              0.9.1                    py27_0  \n",
      "cython                    0.22.1                   py27_0  \n",
      "cytoolz                   0.7.3                    py27_0  \n",
      "datashape                 0.4.5                np19py27_0  \n",
      "decorator                 3.4.2                    py27_0  \n",
      "docutils                  0.12                     py27_1  \n",
      "dynd-python               0.6.5                np19py27_0  \n",
      "enum34                    1.0.4                    py27_0  \n",
      "fastcache                 1.0.2                    py27_0  \n",
      "flask                     0.10.1                   py27_1  \n",
      "funcsigs                  0.4                      py27_0  \n",
      "geopy                     1.11.0                    <pip>\n",
      "geos                      3.4.2                         3  \n",
      "gevent                    1.0.1                    py27_0  \n",
      "gevent-websocket          0.9.3                    py27_0  \n",
      "greenlet                  0.4.7                    py27_0  \n",
      "grin                      1.2.1                    py27_2  \n",
      "h5py                      2.5.0                np19py27_1  \n",
      "hdf5                      1.8.15.1                      2  \n",
      "idna                      2.0                      py27_0  \n",
      "ipaddress                 1.0.7                    py27_0  \n",
      "ipython                   3.2.0                    py27_0  \n",
      "ipython-notebook          3.2.0                    py27_0  \n",
      "ipython-qtconsole         3.2.0                    py27_0  \n",
      "itsdangerous              0.24                     py27_0  \n",
      "jdcal                     1.0                      py27_0  \n",
      "jedi                      0.8.1                    py27_0  \n",
      "jinja2                    2.7.3                    py27_2  \n",
      "jsonschema                2.4.0                    py27_0  \n",
      "launcher                  1.0.0                         1  \n",
      "libpython                 1.0                      py27_1  \n",
      "llvmlite                  0.5.0                    py27_0  \n",
      "lxml                      3.4.4                    py27_0  \n",
      "markupsafe                0.23                     py27_0  \n",
      "matplotlib                1.4.3                np19py27_1  \n",
      "menuinst                  1.0.4                    py27_0  \n",
      "mingw                     4.7                           1  \n",
      "mistune                   0.5.1                    py27_1  \n",
      "mock                      1.3.0                    py27_0  \n",
      "multipledispatch          0.4.7                    py27_0  \n",
      "networkx                  1.9.1                    py27_0  \n",
      "nltk                      3.0.3                np19py27_0  \n",
      "node-webkit               0.10.1                        0  \n",
      "nose                      1.3.7                    py27_0  \n",
      "numba                     0.19.1               np19py27_0  \n",
      "numexpr                   2.4.3                np19py27_0  \n",
      "numpy                     1.9.2                    py27_0  \n",
      "odo                       0.3.2                np19py27_0  \n",
      "openpyxl                  1.8.5                    py27_0  \n",
      "owslib                    0.9.0                    py27_0  \n",
      "pandas                    0.16.2               np19py27_0  \n",
      "patsy                     0.3.0                np19py27_0  \n",
      "pbr                       1.3.0                    py27_0  \n",
      "pep8                      1.6.2                    py27_0  \n",
      "pillow                    2.9.0                    py27_0  \n",
      "pip                       7.1.2                    py27_0  \n",
      "ply                       3.6                      py27_0  \n",
      "proj4                     4.9.1                    py27_1  \n",
      "psutil                    2.2.1                    py27_0  \n",
      "py                        1.4.27                   py27_0  \n",
      "pyasn1                    0.1.7                    py27_0  \n",
      "pycosat                   0.6.1                    py27_0  \n",
      "pycparser                 2.14                     py27_0  \n",
      "pycrypto                  2.6.1                    py27_3  \n",
      "pyepsg                    0.2.0                    py27_0  \n",
      "pyflakes                  0.9.2                    py27_0  \n",
      "pygments                  2.0.2                    py27_0  \n",
      "pyopenssl                 0.15.1                   py27_1  \n",
      "pyparsing                 2.0.3                    py27_0  \n",
      "pyqt                      4.10.4                   py27_1  \n",
      "pyreadline                2.0                      py27_0  \n",
      "pyshp                     1.2.1                    py27_0  \n",
      "pytables                  3.2.0                np19py27_0  \n",
      "pytest                    2.7.1                    py27_0  \n",
      "python                    2.7.10                        0  \n",
      "python-dateutil           2.4.2                    py27_0  \n",
      "pytz                      2015.4                   py27_0  \n",
      "pywin32                   219                      py27_0  \n",
      "pyyaml                    3.11                     py27_2  \n",
      "pyzmq                     14.7.0                   py27_0  \n",
      "requests                  2.7.0                    py27_0  \n",
      "rope                      0.9.4                    py27_1  \n",
      "runipy                    0.1.3                    py27_0  \n",
      "scikit-image              0.11.3               np19py27_0  \n",
      "scikit-learn              0.16.1               np19py27_0  \n",
      "scipy                     0.16.0               np19py27_0  \n",
      "setuptools                18.1                     py27_0  \n",
      "shapely                   1.5.11                 nppy27_0  \n",
      "six                       1.9.0                    py27_0  \n",
      "snowballstemmer           1.2.0                    py27_0  \n",
      "sockjs-tornado            1.0.1                    py27_0  \n",
      "sphinx                    1.3.1                    py27_0  \n",
      "sphinx-rtd-theme          0.1.7                     <pip>\n",
      "sphinx_rtd_theme          0.1.7                    py27_0  \n",
      "spyder                    2.3.5.2                  py27_0  \n",
      "spyder-app                2.3.5.2                  py27_0  \n",
      "sqlalchemy                1.0.5                    py27_0  \n",
      "ssl_match_hostname        3.4.0.2                  py27_0  \n",
      "statsmodels               0.6.1                np19py27_0  \n",
      "sympy                     0.7.6                    py27_0  \n",
      "tables                    3.2.0                     <pip>\n",
      "theano                    0.7.0                     <pip>\n",
      "toolz                     0.7.2                    py27_0  \n",
      "tornado                   4.2                      py27_0  \n",
      "ujson                     1.33                     py27_0  \n",
      "unicodecsv                0.9.4                    py27_0  \n",
      "werkzeug                  0.10.4                   py27_0  \n",
      "wheel                     0.24.0                   py27_0  \n",
      "xlrd                      0.9.3                    py27_0  \n",
      "xlsxwriter                0.7.3                    py27_0  \n",
      "xlwings                   0.3.5                    py27_0  \n",
      "xlwt                      1.0.0                    py27_0  \n",
      "zlib                      1.2.8                         0  \n"
     ]
    }
   ],
   "source": [
    "!conda list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第一次安装好 [Anaconda](http://www.continuum.io/downloads) 以后，可以在命令行输入以下命令使 [Anaconda](http://www.continuum.io/downloads) 保持最新：\n",
    "\n",
    "    conda update conda\n",
    "    conda update anaconda\n",
    "\n",
    "conda 是一种很强大的工具，具体用法可以参照它的[文档](http://conda.pydata.org/docs/)。\n",
    "\n",
    "也可以参考它的 [cheat sheet](http://conda.pydata.org/docs/_downloads/conda-cheatsheet.pdf) 来快速查看它的用法。\n",
    "\n",
    "可以使用它来安装，更新，卸载第三方的 **python** 工具包：\n",
    "\n",
    "    conda install <some package>\n",
    "    conda update <some package>\n",
    "    conda remove <some package>\n",
    "\n",
    "在安装或更新时可以指定安装的版本号，例如需要使用 `numpy 1.8.1`：\n",
    "\n",
    "    conda install numpy=1.8.1\n",
    "    conda update numpy=1.8.1\n",
    "\n",
    "查看 `conda` 的信息：\n",
    "\n",
    "    conda info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current conda install:\n",
      "\n",
      "             platform : win-64\n",
      "        conda version : 3.17.0\n",
      "  conda-build version : 1.14.1\n",
      "       python version : 2.7.10.final.0\n",
      "     requests version : 2.7.0\n",
      "     root environment : C:\\Anaconda  (writable)\n",
      "  default environment : C:\\Anaconda\n",
      "     envs directories : C:\\Anaconda\\envs\n",
      "        package cache : C:\\Anaconda\\pkgs\n",
      "         channel URLs : https://repo.continuum.io/pkgs/free/win-64/\n",
      "                        https://repo.continuum.io/pkgs/free/noarch/\n",
      "                        https://repo.continuum.io/pkgs/pro/win-64/\n",
      "                        https://repo.continuum.io/pkgs/pro/noarch/\n",
      "          config file : None\n",
      "    is foreign system : False\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!conda info"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一个很棒的功能是 `conda` 可以产生一个自定义的环境，假设在安装的是 **Python 2.7** 的情况下，想使用 **Python 3.4**，只需要在命令行下使用 `conda` 产生一个新的环境：\n",
    "\n",
    "    conda create -n py34 python=3.4\n",
    "\n",
    "这里这个环境被命名为 `py34` ，可以根据喜好将 `py34` 改成其他的名字。\n",
    "\n",
    "使用这个环境时，只需要命令行下输入：\n",
    "\n",
    "``` python\n",
    "activate py34 #(windows)\n",
    "source activate py34 #(linux, mac)\n",
    "```\n",
    "\n",
    "此时，我们的 **Python** 版本便是 **`python 3.4`**了。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## spyder 编辑器"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Anaconda` 默认使用的编辑器是 `spyder`，可以在命令行下输入：\n",
    "\n",
    "    spyder\n",
    "\n",
    "来进入这个编辑器，具体使用方法不做介绍。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
